#pragma once

#include <cmath>

#include "Config.h"

namespace ConvCPU {
	void SeparableConvX(float* Output, const float* Input, const float* Kernel, const int& W, const int& H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				float Sum = 0.f;
				for (int r = std::max(-j, -KERNEL_RADIUS); r <= std::min(W - j - 1, KERNEL_RADIUS); r++)
					Sum += Input[i * W + (j + r)] * Kernel[r + KERNEL_RADIUS];
				Output[i * W + j] = Sum;
			}
		}
	}

	void SeparableConvY(float* Output, const float* Input, const float* Kernel, const int& W, const int& H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				float Sum = 0.f;
				for (int r = std::max(-i, -KERNEL_RADIUS); r <= std::min(H - i - 1, KERNEL_RADIUS); r++)
					Sum += Input[(i + r) * W + j] * Kernel[r + KERNEL_RADIUS];
				Output[i * W + j] = Sum;
			}
		}
	}
}